home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / getApplicationVersionAsFloat < prev    next >
Encoding:
Text File  |  2003-07-17  |  3.1 KB  |  98 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  10.May.2002
  22. //
  23. //<doc>
  24. //<name getApplicationVersionAsFloat>
  25. //<owner "Alias|Wavefront">
  26. //
  27. //<synopsis>
  28. //        getApplicationVersionAsFloat()
  29. //
  30. //<returns>
  31. //        float : Value containing the major and minor version numbers.
  32. //
  33. //<description>
  34. //        Return the application version number as a float value.
  35. //        <p>
  36. //        If you use the "about -version" command you get a string
  37. //        value containing the application version. Strings of course
  38. //        may not be used in comparisons like:
  39. //        <p>
  40. //        if ($version > 3.5) { ... };
  41. //        <p>
  42. //        This procedure will return a float value containing the
  43. //        major and minor version number. The major version will be
  44. //        separated from the minor version by a decimal. For example,
  45. //        4.0.3 will return a float value of 4.03.
  46. //
  47. //<examples>
  48. //    if (getApplicationVersionAsFloat() >= 2.5) {
  49. //        print ("Running version 2.5 or higher\n");
  50. //    };
  51. //
  52. //</doc>
  53. //
  54. global proc float getApplicationVersionAsFloat()
  55. {
  56.     float $version = 0.0;
  57.     string $result;
  58.     string $versionString = `about -version`;
  59.  
  60.     //    The following regular expression will ensure a string begins 
  61.     //    with a digit and strip out any non-numeric characters. You will be 
  62.     //    left with a result that looks like the following (where N is 
  63.     //    one more digits).
  64.     //
  65.     //    N
  66.     //    N.N
  67.     //    N.N.N
  68.     //    N.N.N.N
  69.     //
  70.     string $regularExpression = "^[0-9]+[.]*[0-9]*[.]*[0-9]*[.]*[0-9]*";
  71.     $result = `match $regularExpression $versionString`;
  72.     if ("" != $result) {
  73.         //
  74.         //    Determine the major, minor and patch numbers by tokenizing
  75.         //    the string with the period character.
  76.         //
  77.         //    The first token will become the whole value left of the
  78.         //    decimal point. The remaing tokens will be appended together
  79.         //    to form the fractional part to the right of the decimal.
  80.         //
  81.         //    For example, N.N.N.N will become N.NNN.
  82.         //
  83.         string $tokenArray[];
  84.         int $tokenCount;
  85.         $tokenCount= `tokenize $result "." $tokenArray`;
  86.         $result = "";
  87.         for ($index = 0; $index < $tokenCount; $index++) {
  88.             $result += $tokenArray[$index];
  89.             if ($index == 0 && $tokenCount > 1) {
  90.                 $result += ".";
  91.             }
  92.         }
  93.         $version = $result;
  94.     }
  95.  
  96.     return $version;
  97. }
  98.